package com.tyk.bookstore.back.auth.controller;

import com.tyk.bookstore.back.auth.model.query.CodeLoginQuery;
import com.tyk.bookstore.back.auth.model.query.PasswordLoginQuery;
import com.tyk.bookstore.back.auth.model.query.SendMsgCodeQuery;
import com.tyk.bookstore.back.auth.service.LoginService;
import com.tyk.bookstore.back.common.core.model.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "认证服务", description = "认证服务")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/auth/login")
public class LoginController {

    private final LoginService loginService;

    @Operation(summary = "密码登录", description = "密码登录，返回用户令牌")
    @PostMapping("pwd")
    public R<String> loginByPwd(@Validated @RequestBody PasswordLoginQuery query) {
        return R.ok(loginService.loginByPwd(query));
    }

    @Operation(summary = "发送验证码(含行为验证码校验)", description = "发送验证码(含行为验证码校验)")
    @PostMapping("code/msg/check-send")
    public R<String> sendMsgCode(@Validated @RequestBody SendMsgCodeQuery query) {
        return R.ok(loginService.sendMsgCode(query));
    }

    @Operation(summary = "验证码登录", description = "验证码登录")
    @PostMapping("code")
    public R<String> loginByCode(@Validated @RequestBody CodeLoginQuery query) {
        return R.ok(loginService.loginByCode(query));
    }

}
